package com.usian.controller;

import com.usian.pojo.User;
import com.usian.pojo.Zhuce;
import com.usian.service.UserService;
import com.usian.service.ZhuceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/zhuce")
public class ZhuceController {
    @Autowired
    private ZhuceService zhuceService;

//    private static final Logger logger= LoggerFactory.getLogger(ZhuceController.class);

//    @Autowired
//    private DruidDataSource druidDataSource;

//    @RequestMapping("/user")
//    public String User(){
//        return "我的第一个springboot项目";
//    }
//
//    @RequestMapping("/index")
//    public String index(Model model){
//        model.addAttribute("msg","您好");
//        return "index";
//    }
//
//    @RequestMapping("/emp/{id}")
//    public String emp(@PathVariable("id")String id,String name,Model model){
//        model.addAttribute("id",id);
//        model.addAttribute("name",name);
//        return "index";
//    }
//
//    @RequestMapping("testJunit")
//    @ResponseBody
//    public String testJunit(){
//        return "测试junit";
//    }


//    public static void main(String[] args) {
//        String username="abcdefghijklmnopqrstuvwxyz";
//        System.out.println(username.indexOf("e"));
//        String username1="abcdefghijklmneopqrstuvwxyz";
//        System.out.println(username1.lastIndexOf("e"));
//        System.out.println(username.substring(0,2));//从下标开始截取几个字符
//    }

    /**
     * 查询所有用户信息
     * @param model
     * @return
     */
    @RequestMapping("/findAll")
    public String findAll(Model model){
        List<Zhuce> zhuceList=zhuceService.findAll();
        model.addAttribute("zhuceList",zhuceList);
        return "index";
    }

    @RequestMapping("/toAdd")
    public String toAdd(){
        return "zhuce";
    }

    @RequestMapping("/addZhuce")
    public String addZhuce(Zhuce zhuce) {
        if (zhuce.getPass().equals(zhuce.getPass1())){
            zhuceService.addZhuce(zhuce);
        }else {
            System.out.println("两次密码不正确，请重新注册");
        }
        return "redirect:/clzc/Cldl";
    }
    @RequestMapping("/toEdit")
    public String toEdit(Integer id,Model model){
        User user=zhuceService.editId(id);
        model.addAttribute("user",user);
        return "edit";
    }

    @RequestMapping("/editZhuce")
    public String editZhuce(Zhuce zhuce){
        zhuceService.editZhuce(zhuce);
        return "redirect:/clzc/clzc";
    }
    @RequestMapping("/del")
    public String del(Integer id){
        zhuceService.del(id);
        return "redirect:/clzc/clzc";
    }

}
